var Waterline = require('waterline');
var uuid = require('node-uuid');
var moment = require('moment');

/**
 * 知识中心
 */
module.exports = Waterline.Collection.extend({
    identity: 'knowledgecenter',
    tableName: 'tb_knowledgecenter',
    connection: "mysql",
    attributes: {

        rowId: {
            type: 'string',
            primaryKey: true,
            unique: true,
            required: true,
            uuidv4: true,
            columnName: 'rowid',
            defaultsTo: function () {
                return uuid.v4();
            }
        },
        tag: {
            type: 'string',
            columnName: 'tag'
        },
        fileType: {
            type: 'string',
            columnName: 'fileType',
            // model: 'knowledgegroup'
        },
        knowledgegroup: {
            type: 'string',
            required:true,
            columnName: 'groupId',
            model: 'knowledgegroup'
        },
        content: {
            type: 'string',
            columnName: 'content'
        },
        attachmentName:{
            type: 'string',
            columnName: 'attachment_name'
        },
        attachmentUrl:{
            type: 'string',
            columnName: 'attachment_url'
        },
        createUser:{
          type:"string",
          required:true,
          columnName:'createUser',
        },
        createUid: {
            type: 'string',
            required: true,
            columnName: 'createuid',
            model: 'user'
        },

        toJSON: function () {
            var obj = this.toObject();
            obj.createdAt = moment(obj.createdAt).format('YYYY/MM/DD HH:mm');
            obj.updatedAt = moment(obj.updatedAt).format('YYYY/MM/DD HH:mm');
            return obj;
        }

    }
});
